package cn.ad.util;

import cn.ad.model.Search;
import cn.ad.model.SearchParams;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by zooy on 16-12-28.
 */
public class Utils {

    public static final String FORMAT_ONE = "yyyy-MM-dd HH:mm:ss";
    public static final String LONG_DATE_FORMAT = "yyyy-MM-dd";

    public Utils() {
    }

    public static <T> Set<T> list2Set(List<T> list) {
        return new HashSet(list);
    }

    public static Date getStartTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
        return calendar.getTime();
    }

    public static void main(String[] args) {
        Date d = getStartTime(new Date());
        System.out.println(d);
    }

    public static Date stringtoDate(String dateStr, String format) {
        Date d = null;
        SimpleDateFormat formater = new SimpleDateFormat(format);

        try {
            formater.setLenient(false);
            d = formater.parse(dateStr);
        } catch (Exception var5) {
            d = null;
        }

        return d;
    }

    public static String currDay() {
        return dateToString(new Date(), "yyyy-MM-dd");
    }

    public static String dateToString(Date date, String format) {
        String result = "";
        SimpleDateFormat formater = new SimpleDateFormat(format);

        try {
            result = formater.format(date);
        } catch (Exception var5) {
            ;
        }

        return result;
    }

    public static Date getEndTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(11, 23);
        calendar.set(12, 59);
        calendar.set(13, 59);
        calendar.set(14, 999);
        return calendar.getTime();
    }

    public static Date nextDay(Date date, int day) {
        Calendar cal = Calendar.getInstance();
        if(date != null) {
            cal.setTime(date);
        }

        cal.add(6, day);
        return cal.getTime();
    }

    public static void isCurrentTime(Date startTime, Date endTime) {
    }

    public static void resizeSearch(Search search, Date startDate, Date endDate) {
        Date now = getStartTime(Calendar.getInstance().getTime());
        if(startDate.getTime() == now.getTime()) {
            search.setIsToday(0);
        } else if(startDate.getTime() < now.getTime() && endDate.getTime() >= now.getTime()) {
            search.setIsToday(2);
        } else if(endDate.getTime() < now.getTime()) {
            search.setIsToday(1);
        }

    }

    public static void resizeSearch(SearchParams search, Date startDate, Date endDate) {
        Date now = getStartTime(Calendar.getInstance().getTime());
        if(startDate.getTime() == now.getTime()) {
            search.setIsToday(0);
        } else if(startDate.getTime() < now.getTime() && endDate.getTime() >= now.getTime()) {
            search.setIsToday(2);
        } else if(endDate.getTime() < now.getTime()) {
            search.setIsToday(1);
        }

    }
}
